home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / hurd / fd-write.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-30  |  2.5 KB  |  79 lines

  1. /* _hurd_fd_write -- write to a file descriptor; handles job control et al.
  2. Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <hurd.h>
  23. #include <hurd/fd.h>
  24.  
  25. error_t
  26. _hurd_fd_write (struct hurd_fd *fd, const void *buf, size_t *nbytes)
  27. {
  28.   error_t err;
  29.   mach_msg_type_number_t wrote;
  30.   int noctty;
  31.   struct hurd_sigstate *ss;
  32.  
  33.   /* Note that __ioctl.c implements the same SIGTTOU behavior.
  34.      Any changes here should be done there as well.  */
  35.  
  36.   /* Don't use the ctty io port if we are blocking or ignoring SIGTTOU.  */
  37.   ss = _hurd_self_sigstate ();
  38.   noctty = (__sigismember (&ss->blocked, SIGTTOU) ||
  39.         ss->actions[SIGTTOU].sa_handler == SIG_IGN);
  40.   __mutex_unlock (&ss->lock);
  41.  
  42.   err = HURD_FD_PORT_USE
  43.     (fd,
  44.      ({
  45.        const io_t ioport = (!noctty && ctty != MACH_PORT_NULL) ? ctty : port;
  46.        do
  47.      {
  48.        err = __io_write (ioport, buf, *nbytes, -1, &wrote);
  49.        if (ioport == ctty && err == EBACKGROUND)
  50.          {
  51.            if (_hurd_orphaned)
  52.          /* Our process group is orphaned, so we never generate a
  53.             signal; we just fail.  */
  54.          err = EIO;
  55.            else
  56.          {
  57.            /* Send a SIGTTOU signal to our process group.  */
  58.            err = __USEPORT (CTTYID, _hurd_sig_post (0, SIGTTOU, port));
  59.            /* XXX what to do if error here? */
  60.            /* At this point we should have just run the handler for
  61.               SIGTTOU or resumed after being stopped.  Now this is
  62.               still a "system call", so check to see if we should
  63.               restart it.  */
  64.            __mutex_lock (&ss->lock);
  65.            if (!(ss->actions[SIGTTOU].sa_flags & SA_RESTART))
  66.              err = EINTR;
  67.            __mutex_unlock (&ss->lock);
  68.          }
  69.          }
  70.      } while (err == EBACKGROUND);
  71.        err;
  72.      }));
  73.  
  74.   if (! err)
  75.     *nbytes = wrote;
  76.  
  77.   return err;
  78. }
  79.